package epoch.db;

import java.util.Map;

import epoch.game.core.util.EnumUtil;

/**
 * 实体枚举
 * 
 * @author will
 * @date 2016年4月14日 下午7:09:52
 */
public enum EntityEnum {
	PlayerEntity(-1, "t_player"),
	UserEntity(1, "t_user"),
	PlayerMirrorEntity(2, "t_player_mirror"),
	;
	

	public final static int MAX_ENTITY_INDEX=2;
	
	private EntityEnum(int index, String tname) {
		this.index = index;
		this.tableName = tname;
	}

	// 序号，用于传输
	private int index;

	// 表名称
	private String tableName;

	public int getIndex() {
		return index;
	}

	public String getTableName() {
		return tableName;
	}
	
	static Map<Integer,EntityEnum> indexMap;
	static Map<String,EntityEnum> nameMap;
	static{
		indexMap = EnumUtil.toMap(EntityEnum.values(), "index", Integer.class);
		nameMap = EnumUtil.toMap(EntityEnum.values(), "tableName", String.class);
	}
	
	public static EntityEnum indexof(int index){
		return indexMap.get(index);
	}
	
	public static EntityEnum indexof(String tableName){
		return nameMap.get(tableName);
	}

}
